﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

/// <summary>
/// Base64 的摘要说明
/// </summary>
public class Base64
{
    public Base64()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //

    }

    /// <summary>
    /// Base64解密
    /// </summary>
    /// <param name="encodeType">解密采用的编码方式，注意和加密时采用的方式一致</param>
    /// <param name="result">待解密的密文</param>
    /// <returns>解密后的字符串</returns>
    public static string Base64Decode(Encoding encodeType, string result)
    {
        string decode = string.Empty;
        byte[] bytes = Convert.FromBase64String(result);
        try
        {
            decode = encodeType.GetString(bytes);
        }
        catch
        {
            decode = result;
        }
        return decode;
    }    
    /// <summary>
    /// Base64解密，采用utf8编码方式解密
    /// </summary>
    /// <param name="result">待解密的密文</param>
    /// <returns>解密后的字符串</returns>
    public static string Base64Decode(string result)
    {
        return Base64Decode(Encoding.UTF8, result);
    }
}